package com.google.code.p.ivans.serviceinterfacesimpls;



import java.sql.SQLException;
import java.util.List;

import com.google.code.p.ivans.entities.Order;
import com.google.code.p.ivans.entities.Storage;
import com.google.code.p.ivans.entities.Waiter;
import com.google.code.p.ivans.myexceptions.EntityNotFoundException;
import com.google.code.p.ivans.myexceptions.NoLinksException;
import com.google.code.p.ivans.serviceinterfaces.WaiterServiceInterface;

public class WaiterServiceInterfaceImpl implements WaiterServiceInterface {


	public Waiter getByID(long id)  throws EntityNotFoundException, SQLException {		
		return Storage.getInstance().searchWaiterByID(id);
	}

	public List<Waiter> getAllWaiters() throws SQLException, EntityNotFoundException { 
		List<Waiter> rez = Storage.getInstance().getWaiters();
		return rez;
	}


	public void addWaiter(Waiter waiter) throws SQLException {
		Storage.getInstance().addWaiter(waiter);
	}

	public void removeByID(long id)  throws SQLException {
		Storage.getInstance().removeWaiter(id);
	}

	public List<Order> getWaitersOrders(long waiterid)  throws NoLinksException, EntityNotFoundException,SQLException {
		List<Order> rez= Storage.getInstance().OrdersByWaiterId(waiterid);
		return rez;
	}

	//old method
	public void updateWaiter(Waiter waiter, int field) {
		int cur_salary = waiter.getSalary();
		waiter.setSalary((int)(cur_salary + (Math.random() - 1) * cur_salary));
	}	
	
	//�������� ��������� ����, ����� ����� ��������
	public void updateWaiter(long id, int field, Object value) throws EntityNotFoundException, SQLException {
		Storage.getInstance().updateWaiter(id, field, value);
		
	}

	@Override
	public List<Waiter> getAllWaitersByName(int searchType, String... params) throws EntityNotFoundException, SQLException {
		List<Waiter> waiters = Storage.getInstance().getWaitersByName(searchType, params);
		return waiters;
	}

}
